package org.zoffy.security;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.DigestUtils;

import java.util.Arrays;

public class Md5PasswordEncoder implements PasswordEncoder {
    private static final String SALT = "dwadwa9d221+Dwa1";
    @Override
    public String encode(CharSequence rawPassword) {
        return Arrays.toString(DigestUtils.md5Digest((rawPassword.toString()+SALT).getBytes()));
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        if(rawPassword == null || encodedPassword == null){
            return false;
        }
        return encodedPassword.equals(encode(rawPassword));
    }
}
